
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )

function ENT:SetPlayer(ply)
	self:SetOwner(ply)
end

function ENT:MakeActive()
	self.IsActive = true
	self.KillTime = CurTime() + 2.2
end

/*---------------------------------------------------------
   Name: Initialize
---------------------------------------------------------*/
function ENT:Initialize()

	self:SetModel( "models/items/battery.mdl" )
	self:PhysicsInit( SOLID_VPHYSICS )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS ) 
	self:SetColor(225,200,200,255)
	self.EmitOnce = false
	self.Die = false
	self.IsActive = false
	
	self.Color= team.GetColor(self:GetOwner():Team())
	
	local phys = self:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
		phys:EnableDrag(true)
		phys:EnableCollisions(true)
		phys:SetMass(100)
	end
	
	self.Trail = util.SpriteTrail(self, 0, self.Color, false, 5, 2, .3, 1/(5+2)*0.5, "trails/plasma.vmt")
	--[[local trail = ents.Create( "env_spritetrail" )
	
	trail:SetPos( self:GetPos() + (self:GetForward() * -5) )
	trail:SetParent( self )

	trail:SetKeyValue( "targetname", "" )
	trail:SetKeyValue( "parentname", "" )
	trail:SetKeyValue( "lifetime" , "0.38" )
	trail:SetKeyValue( "startwidth", "5.0" )
	trail:SetKeyValue( "endwidth" , "2.5" )
	trail:SetKeyValue( "spritename", "effects/blueblacklargebeam.vmt" )
	trail:SetKeyValue( "renderamt", "205" )
	trail:SetKeyValue( "rendermode", "5" )
	trail:SetKeyValue( "rendercolor", tc.r.." "..tc.g.." "..tc.b )
	trail:SetName("medusa")
	trail:Spawn()
	self.Trail = trail]]
	
end

function ENT:BombExplode()

	self:EmitSound(ChooseRandom(GameSounds.BombExplosion2),140,math.random(110,150))
	
	local effectdata = EffectData()
	effectdata:SetOrigin(self:GetPos())
	util.Effect("clustlet_explosion", effectdata)
	
	self:SmallExplosionDamage(self:GetOwner(),self:GetPos(),60,190)
	
	self.Trail:Fire("kill",1,0.01)
	self:Fire("kill",1,0.001)

end

/*---------------------------------------------------------
   Name: Think
---------------------------------------------------------*/
function ENT:Think()

end 
 
 /*---------------------------------------------------------
   Name: takedamage
---------------------------------------------------------*/
 function ENT:OnTakeDamage( dmginfo )
	
	// React physically when shot/getting blown
	self:TakePhysicsDamage( dmginfo )
	
end


/*---------------------------------------------------------
   Name: PhysicsCollide
---------------------------------------------------------*/
function ENT:PhysicsCollide( data, physobj )
	if data.HitEntity:GetClass() != "bomb_clustlet" or data.HitEntity == nil then
		if (data.Speed > 20 && data.DeltaTime > 0.2 ) then
			self:BombExplode()
		end
	end
end